package cn.iocoder.yudao.module.service.impl;

import cn.iocoder.yudao.module.VO.ClazzVo;
import cn.iocoder.yudao.module.mapper.ClassMapper;
import cn.iocoder.yudao.module.mapper.StudentMapper;
import cn.iocoder.yudao.module.pojo.Clazz;
import cn.iocoder.yudao.module.pojo.Student;
import cn.iocoder.yudao.module.service.ClassService;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassMapper classMapper;
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public void save(ClazzVo clazz) {
        Clazz clazz1 = new Clazz();
       // BeanUtils.copyProperties(clazz1, clazz);
        clazz1.setId(clazz.getId());
        clazz1.setName(clazz.getName());
        classMapper.insert(clazz1);
    }

    @Override
    public void delete(ClazzVo clazz) {
     Long id = clazz.getId();
     classMapper.delete(id);
    }

    @Override
    public void update(ClazzVo clazz) {
     Clazz clazz1 = new Clazz();
        clazz1.setId(clazz.getId());
        clazz1.setName(clazz.getName());
     classMapper.update(clazz1);
    }

    @Override
    public List<Student> findAllStudentByClassId(Long classId) {
        List<Student> studentList = studentMapper.getStudentByClassId(classId);
        return studentList;
    };

    @Override
    public Clazz findById(Long Id){
      return classMapper.getClassById(Id);
    };
}
